package com.xinggq.pay.service.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.xinggq.common.CommonResult;
import com.xinggq.common.page.PageCondition;
import com.xinggq.pay.service.dto.YsePayConfigDTO;
import com.xinggq.pay.service.service.YsePayConfigService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;


/**
 * 银盛支付配置控制器
 *
 * @author xinggq
 */
@Tag(name = "银盛支付配置CRUD")
@SecurityRequirement(name = "X-App-Id")
@RestController
@RequestMapping("/config/yse")
@RequiredArgsConstructor
public class YsePayConfigController {

  private final YsePayConfigService ysePayConfigService;

  @Operation(summary = "创建配置")
  @PostMapping("/create")
  public CommonResult<Void> create(@Validated @RequestBody YsePayConfigDTO dto) {
    ysePayConfigService.create(dto);
    return CommonResult.ok();
  }

  @Operation(summary = "更新配置")
  @PostMapping("/update")
  public CommonResult<YsePayConfigDTO> update(@Validated @RequestBody YsePayConfigDTO dto) {
    ysePayConfigService.update(dto);
    return CommonResult.ok();
  }

  @Operation(summary = "删除配置")
  @GetMapping("/del/{id}")
  public CommonResult<Void> delete(@Parameter(description = "配置ID") @PathVariable Long id) {
    ysePayConfigService.delete(id);
    return CommonResult.ok();
  }

  @Operation(summary = "获取配置详情")
  @GetMapping("/get/{id}")
  public CommonResult<YsePayConfigDTO> getById(
      @Parameter(description = "配置ID") @PathVariable Long id) {
    return CommonResult.ok(ysePayConfigService.getDetail(id));
  }

  @Operation(summary = "分页查询配置列表")
  @PostMapping("/page")
  public CommonResult<IPage<YsePayConfigDTO>> page(
      @Validated @RequestBody PageCondition<YsePayConfigDTO> page) {
    return CommonResult.ok(ysePayConfigService.pageQuery(page));
  }

}